/*   1:    */ package gov.sat.tax.fwsk.common;
/*   2:    */ 
/*   3:    */ import java.io.PrintStream;
/*   4:    */ import java.sql.Connection;
/*   5:    */ import java.util.Hashtable;
/*   6:    */ import javax.naming.Context;
/*   7:    */ import javax.naming.InitialContext;
/*   8:    */ import javax.sql.DataSource;
/*   9:    */ 
/*  10:    */ public class ConnectionPoolBean
/*  11:    */ {
/*  12: 17 */   private static ConnectionPoolBean handler = null;
/*  13: 18 */   private static Hashtable hsTable = new Hashtable();
/*  14: 19 */   private static String aDefaultDataSource = "htFwskDS";
/*  15: 20 */   private static DataSource ds = null;
/*  16:    */   
/*  17:    */   public ConnectionPoolBean()
/*  18:    */   {
/*  19: 28 */     createDataSource(aDefaultDataSource);
/*  20:    */   }
/*  21:    */   
/*  22:    */   public boolean closeConnection(Connection conn)
/*  23:    */   {
/*  24: 37 */     boolean bRetn = true;
/*  25: 39 */     if (conn != null) {
/*  26:    */       try
/*  27:    */       {
/*  28: 42 */         conn.close();
/*  29:    */       }
/*  30:    */       catch (Exception e)
/*  31:    */       {
/*  32: 45 */         bRetn = false;
/*  33: 46 */         System.out.println("Close connection exception: " + e.getMessage());
/*  34:    */       }
/*  35:    */     }
/*  36: 50 */     return bRetn;
/*  37:    */   }
/*  38:    */   
/*  39:    */   private boolean createDataSource(String dbName)
/*  40:    */   {
/*  41: 60 */     if (ds != null) {
/*  42: 61 */       return true;
/*  43:    */     }
/*  44:    */     try
/*  45:    */     {
/*  46: 67 */       hsTable.put(
/*  47: 68 */         "java.naming.factory.initial", 
/*  48: 69 */         "weblogic.jndi.WLInitialContextFactory");
/*  49:    */       
/*  50:    */ 
/*  51: 72 */       Context ctx = new InitialContext(hsTable);
/*  52:    */       
/*  53: 74 */       ds = (DataSource)ctx.lookup(dbName);
/*  54:    */       
/*  55:    */ 
/*  56: 77 */       return true;
/*  57:    */     }
/*  58:    */     catch (Exception e)
/*  59:    */     {
/*  60: 81 */       System.out.println("Naming service exception: " + e.getMessage());
/*  61:    */     }
/*  62: 83 */     return false;
/*  63:    */   }
/*  64:    */   
/*  65:    */   public Connection getConnection()
/*  66:    */   {
/*  67: 93 */     Connection conn = null;
/*  68: 95 */     if (ds != null) {
/*  69:    */       try
/*  70:    */       {
/*  71: 99 */         conn = ds.getConnection();
/*  72:    */       }
/*  73:    */       catch (Exception e)
/*  74:    */       {
/*  75:103 */         System.out.println(
/*  76:104 */           "Get connection, process, or close statement exception: " + 
/*  77:105 */           e.getMessage());
/*  78:    */       }
/*  79:    */     } else {
/*  80:109 */       System.out.println("Get DataSource --" + aDefaultDataSource + " Failed!");
/*  81:    */     }
/*  82:111 */     return conn;
/*  83:    */   }
/*  84:    */   
/*  85:    */   public static synchronized ConnectionPoolBean getHandle()
/*  86:    */   {
/*  87:119 */     if (handler == null) {
/*  88:120 */       init();
/*  89:    */     }
/*  90:121 */     return handler;
/*  91:    */   }
/*  92:    */   
/*  93:    */   private static synchronized void init()
/*  94:    */   {
/*  95:129 */     if (handler != null) {
/*  96:130 */       return;
/*  97:    */     }
/*  98:132 */     handler = new ConnectionPoolBean();
/*  99:    */   }
/* 100:    */ }


/* Location:           D:\htjs\document\wsrz\WsrzEjbInf\
 * Qualified Name:     gov.sat.tax.fwsk.common.ConnectionPoolBean
 * JD-Core Version:    0.7.0.1
 */